package shiqi.ProxyPattern.Permission;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//权限代理类,要实现共同的接口，并关联真实对象

public class PermissionProxy implements AbstractPermission{

    private RealPermisson realPermisson;

    private int level;

    @Override
    public void modifyUserInfo() {
        if (level == 0) {
            System.out.println("对不起，您没有修改用户信息的权限");
        } else if (level == 1) {
            realPermisson.modifyUserInfo();
        }
    }

    @Override
    public void viewNote() {
        System.out.println("查看帖子");
    }

    @Override
    public void publishNote() {
        if (level == 0) {
            System.out.println("对不起，您没有发布新帖的权限");
        } else if (level == 1) {
            realPermisson.publishNote();
        }
    }

    @Override
    public void modifyNote() {
        if (level == 0) {
            System.out.println("对不起，您没有修改帖子的权限");
        } else if (level == 1) {
            realPermisson.modifyNote();
        }
    }

    @Override
    public void setLevel(int level) {
        this.level = level;
    }

    public void setRealPermisson(RealPermisson realPermisson) {
        this.realPermisson = realPermisson;
    }
}
